package spring.board;

import java.io.IOException;
import java.lang.ProcessBuilder.Redirect;
import java.security.Principal;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;
import javax.sql.rowset.serial.SerialException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import spring.board.service.MainService;
import spring.board.vo.Comments;
import spring.board.vo.FriendlistVO;


@Controller
public class CommentsController {
	
	@Autowired
	private MainService mainService;
	
	@Autowired
	private Comments comments;
	
	@RequestMapping(value = "/writeComment/{num}.do")
	public String writeComment(@PathVariable("num") String num, @RequestParam(value="comment") String comment, @ModelAttribute Comments comments, Principal principal) throws Exception {
		
		System.out.println(comment);
		System.out.println(num);
		comments.setComment(comment);
		comments.setUsername(principal.getName());
		comments.setNum(num);
		mainService.writeComment(comments);
		
		return "redirect:/main.do";
		
	}

<<<<<<< .mine
	@RequestMapping(value ="/getComments/{num}.do")
	public String getComments(@PathVariable("num") int num ,Model model) {
		System.out.println("my name's troy");
		List<Comments> comments;
		comments = mainService.getComments(num);
		model.addAttribute("comments", comments);

		return "redirect:/main.do";
		
			 }

=======
>>>>>>> .r48
}